package com.farmproduct.controller;

import com.farmproduct.pojo.Product;
import com.farmproduct.pojo.SellUser;
import com.farmproduct.service.BackMesService;
import com.farmproduct.service.ProductService;
import com.farmproduct.service.SellUserService;
import com.farmproduct.vo.ConditionSearch;
import com.farmproduct.vo.IndexInit;
import com.farmproduct.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/default")
@CrossOrigin
public class DefaultController {
    @Autowired
    private BackMesService backMesService;
    @Autowired
    private ProductService productService;
    @Autowired
    private SellUserService sellUserService;


    @RequestMapping(value = "/initNum/{uid}")
    public ResultVO initConunt(@PathVariable String uid){
        IndexInit indexInit
                = new IndexInit(backMesService.getNoConuntByUid(uid),
                                backMesService.getYesConuntByUid(uid),
                                productService.getProductConuntByUid(uid),
                                sellUserService.getUserConunt());
        if (indexInit!=null){
            return new ResultVO(200,"success",0,indexInit);
        }
        return new ResultVO();
    }

    @RequestMapping(value = "/getproductorder/{uid}")
    public ResultVO getproductorder(@PathVariable String  uid){
        List<Product> productByUidOrder = productService.getProductByUidOrder(uid);
        if (productByUidOrder!=null){
            return new ResultVO(200,"success",0,productByUidOrder);
        }
        return new ResultVO();
    }


}
